#include "LocationCursorByRange.h"

namespace dwarf {

LocationCursorByRange::LocationCursorByRange(const void *_first, const void *_last)
		: first_(_first),
		  last_(_last),
		  current_(first_) {
}

LocationCursorByRange::LocationCursorByRange(const void *_first, size_t _size)
		: first_(_first),
		  last_((const char *) first_ + _size),
		  current_(first_) {
}

LocationCursorByRange::~LocationCursorByRange() {
}

Location LocationCursorByRange::fetch(Dwarf_Unsigned _byteSize) {
	if (current_ == last_) {
		return Location(Location::TYPE_END);
	}
	const void *current = current_;
	Dwarf_Unsigned byteSize = (const char *) last_ - (const char *) current;
	if (byteSize > _byteSize) {
		byteSize = _byteSize;
	}
	current_ = (const char *) current + byteSize;
	return Location(Location::TYPE_ADDRESS, current, byteSize);
}

}
